package com.wanho.java157.ProductManagement.controller;


import com.wanho.java157.ProductManagement.mapper.InventoryMapper;
import com.wanho.java157.ProductManagement.po.Product;
import com.wanho.java157.ProductManagement.po.ProductInventory;
import com.wanho.java157.ProductManagement.po.Store;
import com.wanho.java157.ProductManagement.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/inventory")
@SessionAttributes({"productInventories","inventoryList"})
public class InventoryController {
    @Autowired
    private InventoryService inventoryService;

@RequestMapping("/list")
    public String li(Model model){
        List<ProductInventory> productInventories = inventoryService.selectAll();
        model.addAttribute("productInventories",productInventories) ;
        System.out.println(productInventories);
        return "view/productManage/stock-detail/index";}


    @RequestMapping("/modify")
    public String modify(Model model){
        List<ProductInventory> productInventories = inventoryService.selectAll();

        model.addAttribute("productInventories",productInventories) ;
        System.out.println(productInventories);
        return "view/productManage/stock-detail/index";}


    @RequestMapping("/searchByAbName")
    public String searchByAbName(String name,Model model){
        List<ProductInventory> productInventories = inventoryService.selectAb("%" + name + "%");
        model.addAttribute("productInventories",productInventories);
        System.out.println(productInventories);
        return "view/productManage/stock-detail/index";}

    @RequestMapping("/updateView")
    public String view(Model model, int id) {
        ProductInventory productInventory = inventoryService.selectById(id);
        model.addAttribute("productInventory",productInventory);
        return "view/productManage/stock-detail/update";
    }


    
}
